<include file="Member:leftmenu" />
<div class="content-right fl">
    <h1 class="content-right-title">编辑用户信息</h1>
    

<form id="form" aciton="/admin/member/edituserajax/?edit_uid=<?php echo get('edit_uid');?>" method="post" id="add" onsubmit="return false">

<div class="panel-single panel-single-light mgt20">

    
    <div class="formitems">
        <label class="fi-name">微信头像：</label>
        <div class="form-controls">
            <img src="<?php echo $userinfo['headimgurl'];?>" width="100">
        </div>
    </div>
    
    <div class="formitems">
        <label class="fi-name">微信昵称：</label>
        <div class="form-controls">
            <?php echo $userinfo['nickname'];?>
        </div>
    </div>
    
    <div class="formitems">
        <label class="fi-name">用户ID：</label>
        <div class="form-controls">
            <?php echo $userinfo['uid'];?>
            <input type="hidden" name="uid" value="<?php echo $userinfo['uid'];?>">
        </div>
    </div>
    
    <div class="formitems">
        <label class="fi-name">真实姓名：</label>
        <div class="form-controls">
            <input type="text" class="input xxlarge" name="realname" value="<?php echo $userinfo['realname'];?>" maxlength="20">
            <span class="fi-help-text">用户的真实姓名</span>
        </div>
    </div>

    <div class="formitems">
        <label class="fi-name">用户手机号：</label>
        <div class="form-controls">
            <input type="text" class="input xxlarge" name="mobile" value="<?php echo $userinfo['mobile'];?>" maxlength="11">
            <span class="fi-help-text">用户的手机号码</span>
        </div>
    </div>
    
    <div class="formitems">
        <label class="fi-name">用户微信号：</label>
        <div class="form-controls">
            <input type="text" class="input xxlarge" name="wechat_id" value="<?php echo $userinfo['wechat_id'];?>" maxlength="20">
            <span class="fi-help-text">用户的微信号</span>
        </div>
    </div>
    
    <div class="formitems" >
        <label class="fi-name">用户等级：</label>
        <div class="form-controls">
          
            <select name="grade_id" class="select samll newselect">
            <?php foreach($grade_arr as $k=>$v){?>
                <option value="<?php echo $k;?>" <?php echo ($userinfo['grade_id']==$k) ? "selected":'';?> ><?php echo $v;?></option>
			<?php } ?>
  			</select>
            <span class="fi-help-text" style="color:red;">请慎重更改 <a target="_blank" href="/admin/member/grade">查看等级说明</a></span>
        </div>
    </div>
    
    <div class="formitems" style="display:none">
        <label class="fi-name">聘级：</label>
        <div class="form-controls">
            <select name="pinji_id" class="select samll newselect">
            <?php foreach($pinji_arr as $k=>$v){?>
                <option value="<?php echo $k;?>" <?php echo ($userinfo['pinji_id']==$k) ? "selected":'';?> ><?php echo $v;?></option>
			<?php } ?>
  			</select>
            <span class="fi-help-text" style="color:red;">请慎重更改 <a target="_blank" href="/admin/member/grade">查看等级说明</a></span>
        </div>
    </div>
    
    

    <div class="formitems">
        <label class="fi-name">可用<?php echo C('YONGJIN_NAME');?>：</label>
        <div class="form-controls">
            <input disabled type="text" class="input mini" name="money" value="<?php echo $userinfo['money'];?>">
            <span class="fi-help-text" style="color:red;">用户的佣金, 请慎重更改</span>
        </div>
    </div>
    
    <div class="formitems" style="display:none">
        <label class="fi-name">可用<?php echo C('SCORE_NAME');?>：</label>
        <div class="form-controls">
            <input disabled type="text" class="input mini" name="score" value="<?php echo $userinfo['score'];?>">
            <span class="fi-help-text" style="color:red;">用户的购物微币, 请慎重更改</span>
        </div>
    </div>
    
    <div class="formitems">
        <label class="fi-name">可用<?php echo C('CASH_NAME');?>：</label>
        <div class="form-controls">
            <input disabled type="text" class="input mini" name="cash_money" value="<?php echo $userinfo['cash_money'];?>">
            <span class="fi-help-text" style="color:red;">用户的充值微币, 请慎重更改</span>
        </div>
    </div>
    
    <div class="formitems">
        <label class="fi-name">已提现金额：</label>
        <div class="form-controls">
            <input disabled type="text" class="input mini" name="tixian" value="<?php echo $userinfo['tixian'];?>" disabled>
            <span class="fi-help-text" style="color:red;">已经提现完成的金额, 请慎重更改</span>
        </div>
    </div>
    
    <div class="formitems">
        <label class="fi-name">用户上级手机号码：</label>
        <div class="form-controls">
            <input type="text" id="mobileNumber" class="input large" name="topUserMobile" autocomplete="off">
            <span class="fi-help-text" style="color:red;">如需修改推荐人，请填写用户的上级用户手机号或姓名, 请慎重更改</span>
            <div class="matchs fi-help-text" style="width:400px;position:absolute;z-index:999999"></div>
        </div>
        
		
    </div>
    
    <div class="formitems">
        <label class="fi-name">用户上级姓名：</label>
        <div class="form-controls" id="topUser">
            <?php echo $userinfo['refer_nickname'];?>
        </div>
    </div>
    
    <div class="formitems">
        <label class="fi-name">用户上级id：</label>
        <div class="form-controls" id="topUserId">
            <?php echo $userinfo['refer_uid'];?>
        </div>
    </div>
    
    <div class="formitems" style="display:none">
        <label class="fi-name">用户上级id：</label>
        <div class="form-controls">
            <input type="text" id="refer_uid"  class="input mini" name="refer_uid" value="<?php echo $userinfo['refer_uid'];?>" readonly>
            <span class="fi-help-text" style="color:red;">请填写用户的上级用户id, 请慎重更改</span>
        </div>
    </div>
    
    
    

</div>


<?php if($admininfo['role_id'] == 1){ ?>
<div class="panel-single panel-single-light mgt20 txtCenter">
    <a href="javascript:tijiao();" class="btn btn-primary j-add">我确认无误并提交修改</a>
    
     <a href="/admin/member/edituser/?edit_uid=<?php echo get('edit_uid');?>" class="btn btn-warning">取消</a>
</div>
<?php } ?>

</form>

</div>
<script>

function tijiao(){
	var title = "以上数据非常重要,你确定要继续提交新数据吗?";

	layer.confirm(title, {
	    btn: ['确定','我再想想'] //按钮
	}, function(){
		weSubmit();
	}, function(){
		layer.msg('你取消了提交', {icon: 7});
	});
}


function weSubmit(){

	$.ajax({
		url : '/admin/member/edituserajax?edit_uid=<?php echo get("edit_uid");?>',
		type : "POST",
		data : $('#form').serialize(),
		dataType : 'json',
		async : false,
		success : function(data) {
			layer.closeAll('loading');//关闭正在加载
			if(data.ret == 0){
				// 成功
				var messagetype = 1;
			}else{
				// 失败
				var messagetype = 2;
			}
			if (data.url) {
				// 如果有跳转地址
				layer.msg(data.msg,{icon: messagetype}, function(){
					window.location.href = data.url;//跳转
				}); 
				
			} else {
				layer.msg(data.msg, {icon: messagetype});
			}
		},
		beforeSend:function(){
			layer.load();//正在加载
       },
       error: function() {
		   layer.closeAll('loading');//关闭正在加载
		   layer.msg("网络错误,请重试", {icon: 2});
       }
       
	});
}
//根据上级推荐人手机号匹配用户
$("#mobileNumber").keyup(function(){
	var str = $(this).val();
	var self = $(this);
	
	var refer_uid = "<?php echo $userinfo['refer_uid'];?>";
	var refer_name = "<?php echo $userinfo['refer_nickname'];?>";
	//输入第三位手机号时开始匹配
	if(str){
		$.ajax({
			url:"/admin/common/matchmember",
			type:"post",
			data:{str:str},
			dataType:"json",
			success:function(data){
				
				console.log(data);
				var dom = $(".matchs");
				dom.html("");
				$.each(data,function(){
					//memberAccount = data;
					var html = '<div class="match" data-mobile='+this.mobile+' data-uid='+this.uid+'	data-realname='+(this.realname?this.realname:this.nickname)+' style="padding:5px 20px;background-color:#D3D3D3;border-bottom:2px solid white;" >姓名：'+(this.realname?this.realname:this.nickname)+' 手机号码：'+this.mobile+'</div>';
					dom.append(html);
				});
				$(".match").on("click",function(){
					
					var mobile = $(this).attr('data-mobile');
					var uid = $(this).attr('data-uid');
					var realname = $(this).attr('data-realname');
					self.val(mobile);
					$("#topUser").text(realname);
					$("#topUserId").text(uid);
					$("#refer_uid").val(uid);
					dom.html("");
				});
			},
			error:function(){
				$(".matchs").html("");
				$("#topUser").text(refer_name);
				$("#topUserId").text(refer_uid);
				$("#refer_uid").val(refer_uid);
			}
		});
	}else{
		$(".matchs").html("");
		$("#topUser").text(refer_name);
		$("#topUserId").text(refer_uid);
		$("#refer_uid").val(refer_uid);
	}
});
</script>